package 基础.static_;

class Dog{
    String name;
    int age;
    static String color;

    public Dog() {
    }

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    static void food1() {
        System.out.println(" 骨头");//静态方法不能出现this
    }

    void food2() {
        System.out.println(this.name+" 肉");
    }


    void like1() {
        //非静态调用静态
        Dog.food1();
        //非静态调用非静态
        this.food2();
    }
    static void like2(){
        //静态调用静态
        Dog.food1();
//        this.food1();//错误

        //静态调用非静态
//        food2();//错误，不可以直接调用
        Dog dog =new Dog();
        dog.food2();

    }
    void show(){
        System.out.println("姓名： "+this.name+" 年龄： "+this.age+" 颜色： "+this.color);
    }

}
public class Static {
    public static void main(String[] args) {
//        static int a =100;//static不能修饰局部变量，只能修饰成员变量


//非静态调用静态
        System.out.println(Dog.color);
        Dog.color = "黑色";
        System.out.println(Dog.color);

        Dog dog =new Dog();
       dog.name ="gg";
       dog.food1();
        dog.like1();

        Dog dog1 =new Dog("小黄",1);
        Dog dog2 =new Dog("中黄",2);
        Dog dog3 =new Dog("大黄",3);
        Dog.color ="黄色";
        dog1.show();
        dog2.show();
        dog3.show();
    }
}
